<?php

namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Support\Facades\Auth;



class Controller extends \Illuminate\Routing\Controller
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $user = null;
    /**
     * check auth construct method
     */
    function __construct()
    {
        $this->middleware('auth');
        if(Auth::check()){
            $this->user = Auth::getUser();
        }
    }

    /**
     * return succed messages
     *
     * @param $msg
     * @param array $data
     * @return array
     * @author: Merdan
     */
    protected function success($msg, $data = [])
    {
        return array('result'=> true, 'message' => $msg, 'data' => $data);
    }

    /**
     * return failed messages
     *
     * @param $msg
     * @param array $data
     * @return array
     * @author: Merdan
     */
    protected function fail($msg, $data = [])
    {
        return array('result'=> false, 'message' => $msg, 'data' => $data);
    }

    /**
     * return when methed not found
     *
     * @param array $parameters
     * @return array
     * @author: Merdan
     */
    public function missingMethod($parameters = array())
    {
        $mess =  _('相关函数不存在');
        return $this->fail($mess);

    }

    /**
     * return success message
     *
     * @return string
     * @author: Merdan
     */
    protected function getSuccessMessage()
    {
        return _('操作成功！');
    }

    /**
     * return
     *
     * @return string
     * @author: Merdan
     */
    protected function getUnknownMessage()
    {
        return _('发生未知错误， 请稍后再试。');
    }
}
